package TestThread;

import java.util.Scanner;

public class demo13 {
    private static final Object locker = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
           synchronized (locker){
               System.out.println("thread1线程wait之前");
               try {
                   locker.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("thread1线程wait之后");
           }
        });
        Thread thread3 = new Thread(() -> {
           synchronized (locker){
               System.out.println("thread3线程wait之前");
               try {
                   locker.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("thread3线程wait之后");
           }
        });
        Thread thread2 = new Thread(() -> {
            synchronized (locker){
                System.out.println("thread2线程notify之前");
                Scanner scanner = new Scanner(System.in);
                System.out.println("随机输入，来触发notify");
                scanner.next();
                locker.notify();
                System.out.println("thread2线程notify之后");
            }
        });
        thread3.start();
        Thread.sleep(100);
        thread1.start();
        Thread.sleep(100);
        thread2.start();
    }
}
